package cn.hesion.Speak;
/**
 * ClassName: SpeekDurationMapper <br/>
 * Description: <br/>
 * date: 2021/2/2 15:06<br/>
 *
 * @author Hesion<br />
 * @version
 * @since JDK 1.8
 */

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @program: ClientDemo
 * @description:
 * @author: hesion
 * @create: 2021-02-02 15:06
 **/
public class SpeakDurationMapper extends Mapper<LongWritable, Text,Text,SpeakBean> {
    SpeakBean v = new SpeakBean();
    Text k = new Text();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        // 读取每行文本
        String line = value.toString();

        //以\t进行分割
        String[] fields = line.split("\t");

        //进行对象的封装
        //取出deviceId,作为key使用
        String deviceId = fields[1];

        long selfDuration = Long.parseLong(fields[fields.length - 3]);
        long thirdDutation = Long.parseLong(fields[fields.length - 2]);



        // 准备k，v
        k.set(deviceId);
        v.set(selfDuration,thirdDutation);

        //4 写出
        context.write(k,v);

    }
}
